<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>$on 与 $emit</title>
    <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <child content="Dell"></child >
      <child content="Bob"></child>
    </div>

    <script>
      Vue.prototype.bus = new Vue();
      Vue.component('child', {
        props: ['content'],
        data: function() {
          return {
            selfContent: this.content
          }
        },
        template: '<div @click="handleClick">{{selfContent}}</div>',
        methods: {
          handleClick: function() {
            this.bus.$emit('change', this.selfContent);
          }
        },
        mounted: function() {
          var _this = this;
          this.bus.$on('change', function(msg) {
            _this.selfContent = msg;
          })
        },
      });
      var vm = new Vue({
        el: '#app',
      })
    </script>
  </body>
</html>
